const question = require('../models/question');

var express = require('express');
var router = express.Router()

var formidable = require('formidable')

router.post('/', (req, res, next) => {
    var form = new formidable.IncomingForm();
    form.parse(req, async function (err, fields, files) {
        if(err) {
            res.json({'state': false, 'msg': 'There is somethin wrong!'});
        }else {
            try{
               let doc = await question.findById(fields.id)
               res.json({
                   'state': true,
                    'answer': doc.answer,
                    'illustrationContent': doc.illustrationContent
               })
            } catch(err){
                console.log(err)
                res.json({
                    'state': false,
                    'msg': err
                })
            }
        }
    });
});

module.exports = router;